﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ModelLibrary;

namespace WebC
{
    public partial class DeviceSelect : clsBaseForm
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadInfo();
            }
        }

        int iDeptId
        {
            get
            {
                return Convert.ToInt32(Request["deptid"]);
            }
        }

        int iProjectId
        {
            get
            {
                return Convert.ToInt32(Request["id"]);
            }
        }

        private void loadInfo()
        {
            BuyDevice buy = null;
            //DeviceInfo deviceinfo = new DeviceInfo();
            DataTable dt = null;
            try
            {
                buy = new BuyDevice();
                dt = buy.getDeviceListByDeptId(0,"");
                //dt = deviceinfo.getDevPartList("", 0, iDeptId, "");
            }
            catch (Exception ex)
            {
                errorUrl(ex.ToString());
            }
            finally
            {
                if (buy != null)
                {
                    buy.Dispose();
                }
            }
            DataGridPart.DataSource = dt;
            DataGridPart.DataBind();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            CheckBox cb;

            //StringBuilder sbu = new StringBuilder();
            ArrayList sbu = new ArrayList();

            foreach (DataGridItem r in this.DataGridPart.Items)
            {

                cb = (CheckBox)r.Cells[1].Controls[1];

                if (cb.Checked)
                {
                    sbu.Add(string.Format(@"<tr>
                        <td align=""left"" width=""120"">
                            <a href=""javascript:"" onclick=""insertdevice(this.parentNode.parentNode)"">+</a> <a href=""javascript:"" onclick=""removeItem(this.parentNode.parentNode)"">-</a><input style=""width: 92px"" type=""text"" value=""{0}"" /><input style=""width: 64px"" type=""hidden"" value=""{1}"" /></td>
                        <td width=""70"">
                            <input  style=""width: 70px"" type=""text"" value=""{2}"" /></td>
                        <td width=""70"">
                            <input  style=""width: 70px"" type=""text"" value=""{3}"" /></td>
                        <td width=""70"">
                            <input  style=""width: 70px"" type=""text"" value=""{4}"" /></td>
                    </tr>", r.Cells[2].Text.Trim(), r.Cells[0].Text.Trim(), r.Cells[3].Text.Trim(), r.Cells[4].Text.Trim(), ""));
                }
            }
            Response.Write("<script language='javascript'>window.returnValue=" + sbu + ";window.close();</script>");
            return;
        }
}
}